package com.socodethis.spaceex;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.socodethis.spaceex.math.cPoint;

public abstract class charClass {
	spriteAnimate movement;
	dungeonGenerator map;
	Sprite sprite;
	float health, startingHealth;
	boolean rendered;
	Sprite temp;
	private float charPosLevel;
	textureHolder texture= new textureHolder();
	cPoint tempPosition = new cPoint(0,0);
	Sprite[] healthBar = {new Sprite(texture.returnHealthBar()[0]),new Sprite(texture.returnHealthBar()[1])};;
	charClass(spriteAnimate movement, dungeonGenerator map){
		this.movement = movement;
		this.map = map;
		sprite = new Sprite();
		startingHealth = 25;
		health = startingHealth;
		rendered = false;
		charPosLevel = 0;
		healthBar[0].setSize(movement.getScale().getX(), movement.getScale().getY());
		healthBar[0].setOrigin(0, 0);
		healthBar[0].setRotation(movement.getRotation());
		healthBar[1].setSize(movement.getScale().getX(), movement.getScale().getY());
		healthBar[1].setOrigin(0, 0);
		healthBar[1].setRotation(movement.getRotation());
	}
	public void setCharPosLevel(float value){
		this.charPosLevel = value;
	}
	public float getCharPosLevel(){
		return this.charPosLevel;
	}
	public void changeDungeon(dungeonGenerator map, cPoint newPosition){
		this.map = map;
		movement.setPosition(newPosition);
	}
	//Should never be referenced directly
	protected void setSprite(float currentTime){
		sprite = movement.returnSprite(currentTime);
		sprite.setPosition((float) (movement.getPosition().getX()+1.5+(movement.getTransitionCount().getX()-charPosLevel))
			, movement.getPosition().getY()+(movement.getTransitionCount().getY()-charPosLevel));
		healthBar[0].setPosition((float) (sprite.getX()-1.5), (float) (sprite.getY()-1));
		healthBar[1].setPosition((float) (sprite.getX()-1.5), (float) (sprite.getY()-1));
	}
	public Sprite returnSprite(){
		return sprite;
	}
	public void drawSprites(SpriteBatch batch){
		temp = healthBar[0];
		//temp = new Sprite(healthBar[0]);
		if (health > 0){
			temp.setScale(health/startingHealth, 1);
		}else{
			temp.setScale(0, 1);
		}
		sprite.draw(batch);
		healthBar[1].draw(batch);
		temp.draw(batch);
	}
	public cPoint getPosition(){
		return movement.getPosition();
	}
	public cPoint getPositionDrawing(){
		return movement.getTransitionPath();
	}
	public float returnDirection(){
		return movement.returnDirection();
	}
	public cPoint getDestination(){
		return movement.getDestination();
	}
	//This is for the camera so that it doesn't skip when the character is being trailed
	public cPoint getSmoothPosition(){
		tempPosition.setPoint(movement.getPosition().getX() + (movement.getTransitionCount().getX()), 
				movement.getPosition().getY() + (movement.getTransitionCount().getY()));
		return tempPosition;
	}
	public boolean isMoving(){
		return movement.isMoving();
	}
	public void stopChar(){
		movement.stopCharacter();
	}
	public void charHit(){
		if (health >= 0){
			health--;
		}
	}
	public void resetHealth(){
		health = startingHealth;
	}
	public void moveChar(cPoint end){
		movement.setSpritePath(map, end);
	}
	public float returnHealth(){
		return health;
	}
	public boolean getRendered(){
		return rendered;
	}
	public void setRendered(boolean value){
		rendered = value;
	}
}
